// page/cart/orderinfo.js
var utils = require('../../utils/util.js');
Page({
	data: {
		info: [],
	},

    /**
     * 生命周期函数--监听页面加载
     */
	onLoad: function (options) {
		var that = this;
		var uid = wx.getStorageSync('uid');
		utils.GET({
			url: 'Cart/getuinfo',
			params: { uid: uid},
			success: function (res) {
				that.setData({
					info: res.data,
				})
			},
		})

	},

    /**
     * 表单验证
     */
	formSubmit: function (e) {
		var uid = wx.getStorageSync('uid');
		var username = e.detail.value.username
		var phone = e.detail.value.phone

		if (username.length < 1) {
			wx.showToast({
				title: '请输入您的姓名',
			})
			return;
		} else if (phone.length < 1) {
			wx.showToast({
				title: '请输入您的手机号',
			})
			return;
		} else {
			//成功
			utils.GET({
				url: 'Cart/adduinfo',
				params: { 
					uid: uid, name: username, mobile: phone
					 },
				success: function (res) {
					console.log(res.data)
					if (res.data.statds) {
						var pages = getCurrentPages();
						var currPage = pages[pages.length - 1];   //当前页面
						var prevPage = pages[pages.length - 2];  //上一个页面

						//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
						prevPage.setData({
							info: username + phone
						})
						wx.showToast({
							title: '信息保存成功',
							icon: 'success',
							duration: 2000,
							complete: function () {

							}
						});
						wx.navigateBack();
					} else {
						
					}
				},
			})
		}
	}
})